#include "WidgetVideo.h"

WidgetVideo::WidgetVideo(QWidget *parent) : QWidget(parent)
{
    initCamera();

    // 把视频显示到 layoutCamera 中
    layoutCamera = new QVBoxLayout();
    layoutCamera->addWidget(cameraViewfinder);
    parent->setLayout(layoutCamera);

}

void WidgetVideo::initCamera(QCamera *camera)
{
    if (camera == NULL)
        this->camera = new QCamera();
    else
        this->camera = camera;

    cameraViewfinder = new QCameraViewfinder();
    this->camera->setViewfinder(cameraViewfinder);

}

void WidgetVideo::startCamera()
{
    // 打开摄像头
    camera->start();
}

void WidgetVideo::stopCamera()
{
    camera->stop();
}

WidgetVideo::~WidgetVideo()
{
    delete camera;
}
